package com.infore.remoteControl.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.infore.remoteControl.service.IFileService;
import com.infore.remoteControl.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "文件管理接口", tags = {"文件管理接口" })
@RestController
@RequestMapping("/file")
public class FileController {
	
	@Autowired
	IFileService iFileService;
	
	@ApiOperation(value = "下载文件")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "fileUrl", value = "文件Url", paramType = "query", required = true, dataType = "String"),
		@ApiImplicitParam(name = "isOnLine", value = "是否在线打开", paramType = "query", required = true, dataType = "boolean")})
	@RequestMapping(value = "/download", method = RequestMethod.GET)
	public void downloadFile(String fileUrl, boolean isOnLine, HttpServletResponse response) {
		iFileService.download(fileUrl, isOnLine, response);
	}
	
	@ApiOperation(value = "上传文件")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "isPath", value = "是否返回文件路径", paramType = "query", required = true, dataType = "boolean")})
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public ResultEntity uploadFile(MultipartFile file, boolean isPath) {
		return iFileService.uploadFile(file, isPath);
	}
	
	@ApiOperation(value = "上传文件")
	@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
	public ResultEntity upload(HttpServletRequest request) {
		return iFileService.upload(request);
	}
	
	@ApiOperation(value = "删除文件")
	@RequestMapping(value = "/deleteFile", method = RequestMethod.POST)
	public ResultEntity deleteFile(String filePath) {
		return iFileService.deleteFile(filePath);
	}
}
